package com.chuji.crmcj.act;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.Response;
import com.chuji.crmcj.R;
import com.chuji.crmcj.utils.ConstantValue;
import com.chuji.crmcj.utils.NumberUtils;
import com.chuji.crmcj.utils.SPUtils;
import com.chuji.crmcj.utils.UIUtils;
import com.chuji.crmcj.utils.UrlUtils;

import org.json.JSONObject;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

public class LendCounterActivity extends BaseActivity implements View.OnClickListener{
    //回退
    private ImageView mIv_Back;
    //历史记录
    private LinearLayout mLl_history;
    //贷款金额
    private EditText mEt_repay_money;
    //贷款利率
    private EditText mEt_repay_rate;
    //贷款年限选择
    private LinearLayout mLl_repay_time;
    //贷款年限显示
    private TextView mTv_repay_time;
    //预计总花费
    private TextView mTv_total_money;
    //月供
    private TextView mTv_repay_month;
    //额外花费
    private TextView mTv_extra_expense;
    //关联客户
    private Button mBtn_relevance_client;
    //显示上拉列表
    private PopupWindow popupwindow;
    private RelativeLayout Rl_title;
    private LinearLayout ll_mian;
    Editable value;
    Editable value1;
    InputMethodManager imm;
    //本金，年利率
    double loan_money;
    double year_rate;
    double month_rate;
    double text1;
    double text2;
    double total;
    //意图
    Intent intent;
    //客户ID
    String CustomerID;
    //销售员ID
    String SalesID;
    //销售员ID
    String FlowID;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lend_counter);
        //初始化组件
        mIv_Back = (ImageView) findViewById(R.id.iv_Back);
        mLl_history = (LinearLayout) findViewById(R.id.ll_history);
        mEt_repay_money = (EditText) findViewById(R.id.et_repay_money);
        mEt_repay_rate = (EditText) findViewById(R.id.et_repay_rate);
        mLl_repay_time = (LinearLayout) findViewById(R.id.ll_repay_time);
        mTv_repay_time = (TextView) findViewById(R.id.tv_repay_time);
        mTv_total_money = (TextView) findViewById(R.id.tv_total_money);
        mTv_repay_month = (TextView) findViewById(R.id.tv_repay_month);
        mTv_extra_expense = (TextView) findViewById(R.id.tv_extra_expense);
        mBtn_relevance_client = (Button) findViewById(R.id.btn_relevance_client);
        Rl_title= (RelativeLayout) findViewById(R.id.Rl_title);
        ll_mian = (LinearLayout) findViewById(R.id.ll_mian);
        //弹出数字键盘
        mEt_repay_money.setInputType(EditorInfo.TYPE_CLASS_PHONE);
        //设置点击事件
        mIv_Back.setOnClickListener(this);
        mLl_history.setOnClickListener(this);
        mLl_repay_time.setOnClickListener(this);
        mBtn_relevance_client.setOnClickListener(this);
        ll_mian.setOnClickListener(this);
        mEt_repay_money.addTextChangedListener(mTextWatcher);
        mEt_repay_rate.addTextChangedListener(mTextWatcher);
        //获取ID
        intent=getIntent();
        CustomerID=intent.getStringExtra("CustomerID");
        FlowID=intent.getStringExtra("FlowID");
        SalesID= SPUtils.getString(UIUtils.getContext(), "UserID", "");
//        //暂时显示金额
//        BigDecimal bd=new BigDecimal(188888);
//        mTv_total_money.setText(NumberUtils.parseMoney(",###,###", bd));
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initListener() {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.iv_Back:
                finish();
                break;
            case R.id.ll_history:
                //跳转到历史记录界面
                UIUtils.startActivity(new Intent(UIUtils.getContext(),LendHistoryActivity.class));
                break;
            case R.id.ll_repay_time:
                //显示选择界面
//                showRepayTime();
//                if (popupwindow != null && popupwindow.isShowing()) {
//                    popupwindow.dismiss();
//                    return;
//                } else {
//                    initmPopupWindowView();
//                    popupwindow.showAsDropDown(view, 0, 5);
//                }
                if(getWindow().getAttributes().softInputMode==WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED)
                {
                //隐藏软键盘
                    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
                }else {
                    showPopwindow();
                }
                break;
            case R.id.btn_relevance_client:
                if(mTv_repay_time.getText().toString().equals("0")||mTv_total_money.getText().toString().equals("0")||mTv_repay_month.getText().toString().equals("0")){
                    UIUtils.showToastSafe("请进行计算后再提交");
                }else {
                    //保存
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("CustomerID", CustomerID);
                    map.put("FlowID", FlowID);
                    map.put("Amount", mEt_repay_money.getText().toString());
                    map.put("Rate", mEt_repay_rate.getText().toString() + "%");
                    map.put("Years", mTv_repay_time.getText().toString());
                    map.put("TotalAmount", mTv_total_money.getText().toString());
                    map.put("MonthAmount ", mTv_repay_month.getText().toString());
                    map.put("SalesID", SalesID);
                    postRequest(UrlUtils.INSERT_LOAN_RECORD, map, new Response.Listener<JSONObject>() {
                        @Override
                        public void onResponse(JSONObject jsonObject) {
                            UIUtils.showToastSafe("提交成功");
                        }
                    });
                    //跳转到搜索界面
                    intent=new Intent(LendCounterActivity.this, SearchActivity.class);
                    intent.putExtra("Lable", ConstantValue.SEARCHSELF);
                    startActivity(intent);
                }
                break;
            case R.id.ll_mian:
                //收起软键盘
                imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                break;
        }
    }
    //获取总的花费,月花费，多花费的
    public void getTotalMoney(double loan_money,double month_rate,double month){
        //总花费
        text1=month_rate*(Math.pow((1 + month_rate), month));
        text2=(Math.pow((1+month_rate),month)-1);
        total=loan_money *(text1/text2)*(month);
        BigDecimal zemvalue = new BigDecimal(total);
        double zemval = zemvalue.setScale(2, BigDecimal.ROUND_HALF_UP)
                .doubleValue();
//        mTv_total_money.setText(String.valueOf(zemval));
        BigDecimal bd1=new BigDecimal(String.valueOf(zemval));
        mTv_total_money.setText(NumberUtils.parseMoney(",###,###.##", bd1));
        BigDecimal bd2=new BigDecimal(String.valueOf(zemval/month));
        mTv_repay_month.setText(NumberUtils.parseMoney(",###,###.##", bd2));
        BigDecimal bd3=new BigDecimal(String.valueOf(zemval-loan_money));
        mTv_extra_expense.setText(NumberUtils.parseMoney(",###,###.##", bd3));
    }
    /**
     * 显示popupWindow
     */
    protected void showPopwindow() {
        // 利用layoutInflater获得View
        View customView = View.inflate(this,R.layout.dialog_repay_time, null);
        // 下面是两种方法得到宽度和高度 getWindow().getDecorView().getWidth()
        popupwindow = new PopupWindow(customView,RadioGroup.LayoutParams.MATCH_PARENT,RadioGroup.LayoutParams.WRAP_CONTENT);
        // 设置popWindow弹出窗体可点击，这句话必须添加，并且是true
        popupwindow.setOutsideTouchable(true);
        popupwindow.setFocusable(true);
        // 实例化一个ColorDrawable颜色为半透明
//        ColorDrawable dw = new ColorDrawable(0xb0000000);
        popupwindow.setBackgroundDrawable(UIUtils.getDrawable(R.drawable.transparent));
        backgroundAlpha(0.5f);
        // 设置popWindow的显示和消失动画
        popupwindow.setAnimationStyle(R.style.main_menu_animstyle);
        // 在底部显示
        popupwindow.showAsDropDown(LendCounterActivity.this.findViewById(R.id.ll_repay_time), UIUtils.dip2px(-100),UIUtils.dip2px(140));
//        popupwindow.showAtLocation(LendCounterActivity.this.findViewById(R.id.ll_repay_time), Gravity.BOTTOM, 0, 0);
        //声明和初始化组件
        LinearLayout mLl_one = (LinearLayout) customView.findViewById(R.id.ll_one);
        LinearLayout  mLl_two = (LinearLayout) customView.findViewById(R.id.ll_two);
        LinearLayout mLl_three = (LinearLayout) customView.findViewById(R.id.ll_three);
        LinearLayout mLl_four = (LinearLayout) customView.findViewById(R.id.ll_four);
        LinearLayout mLl_five = (LinearLayout) customView.findViewById(R.id.ll_five);
        LinearLayout mLl_six = (LinearLayout) customView.findViewById(R.id.ll_six);
        LinearLayout ll_show = (LinearLayout) customView.findViewById(R.id.ll_show);
        //默认选中

        //设置点击事件
        mLl_one.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTv_repay_time.setText("1年12期");
                if(mEt_repay_money.getText().toString() == null||mEt_repay_money.getText().toString().length()==0||mEt_repay_rate.getText().toString() == null||mEt_repay_rate.getText().toString().length() <=0){
                    UIUtils.showToastSafe("贷款金额、年利率不能为空");
                }else{
                    //本金
                    loan_money= Double.parseDouble(mEt_repay_money.getText().toString());
                    //年利率
                    year_rate = (Double.parseDouble(mEt_repay_rate.getText().toString()))/100.0;
                    //月利率
                    month_rate=year_rate/12.0;
                    getTotalMoney(loan_money,month_rate,12.0);
                }
                popupwindow.dismiss();
            }
        });
//        mLl_one.setBackgroundResource(R.color.gray);
        mLl_two.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTv_repay_time.setText("2年24期");
                if(mEt_repay_money.getText().toString() == null||mEt_repay_money.getText().toString().length()==0||mEt_repay_rate.getText().toString() == null||mEt_repay_rate.getText().toString().length() <=0){
                    UIUtils.showToastSafe("贷款金额、年利率不能为空");
                }else{
                    //本金
                    loan_money= Double.parseDouble(mEt_repay_money.getText().toString());
                    //年利率
                    year_rate = (Double.parseDouble(mEt_repay_rate.getText().toString()))/100.0;
                    //月利率
                    month_rate=year_rate/12.0;
                    getTotalMoney(loan_money,month_rate,24.0);
                }
                popupwindow.dismiss();
            }
        });
        mLl_three.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTv_repay_time.setText("3年36期");
                if(mEt_repay_money.getText().toString() == null||mEt_repay_money.getText().toString().length()==0||mEt_repay_rate.getText().toString() == null||mEt_repay_rate.getText().toString().length() <=0){
                    UIUtils.showToastSafe("贷款金额、年利率不能为空");
                }else{
                    //本金
                    loan_money= Double.parseDouble(mEt_repay_money.getText().toString());
                    //年利率
                    year_rate = (Double.parseDouble(mEt_repay_rate.getText().toString()))/100.0;
                    //月利率
                    month_rate=year_rate/12.0;
                    getTotalMoney(loan_money,month_rate,36.0);
                }
                popupwindow.dismiss();
            }
        });
        mLl_four.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTv_repay_time.setText("4年48期");
                if(mEt_repay_money.getText().toString() == null||mEt_repay_money.getText().toString().length()==0||mEt_repay_rate.getText().toString() == null||mEt_repay_rate.getText().toString().length() <=0){
                    UIUtils.showToastSafe("贷款金额、年利率不能为空");
                }else{
                    //本金
                    loan_money= Double.parseDouble(mEt_repay_money.getText().toString());
                    //年利率
                    year_rate = (Double.parseDouble(mEt_repay_rate.getText().toString()))/100.0;
                    //月利率
                    month_rate=year_rate/12.0;
                    getTotalMoney(loan_money,month_rate,48.0);
                }
                popupwindow.dismiss();
            }
        });
        mLl_five.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTv_repay_time.setText("5年60期");
                if(mEt_repay_money.getText().toString() == null||mEt_repay_money.getText().toString().length()==0||mEt_repay_rate.getText().toString() == null||mEt_repay_rate.getText().toString().length() <=0){
                    UIUtils.showToastSafe("贷款金额、年利率不能为空");
                }else{
                    //本金
                    loan_money= Double.parseDouble(mEt_repay_money.getText().toString());
                    //年利率
                    year_rate = (Double.parseDouble(mEt_repay_rate.getText().toString()))/100.0;
                    //月利率
                    month_rate=year_rate/12.0;
                    getTotalMoney(loan_money,month_rate,60.0);
                }
                popupwindow.dismiss();
            }
        });
        mLl_six.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTv_repay_time.setText("6年72期");
                if(mEt_repay_money.getText().toString() == null||mEt_repay_money.getText().toString().length()==0||mEt_repay_rate.getText().toString() == null||mEt_repay_rate.getText().toString().length() <=0){
                    UIUtils.showToastSafe("贷款金额、年利率不能为空");
                }else{
                    //本金
                    loan_money= Double.parseDouble(mEt_repay_money.getText().toString());
                    //年利率
                    year_rate = (Double.parseDouble(mEt_repay_rate.getText().toString()))/100.0;
                    //月利率
                    month_rate=year_rate/12.0;
                    getTotalMoney(loan_money,month_rate,72.0);
                }

                popupwindow.dismiss();
            }
        });
        ll_show.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupwindow.dismiss();
            }
        });
        //popWindow消失监听方法
        popupwindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                backgroundAlpha(1f);
            }
        });
}
//    public void initmPopupWindowView() {
//        // // 获取自定义布局文件pop.xml的视图
//        final View customView = getLayoutInflater().inflate(R.layout.dialog_repay_time,
//                null, false);
//        // 创建PopupWindow实例,WindowManager.LayoutParams.MATCH_PARENT,200分别是宽度和高度
//        popupwindow = new PopupWindow(customView, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
////        popupwindow.setBackgroundDrawable(new ColorDrawable(0xc0000000));
//        // 设置动画效果 [R.style.AnimationFade 是自己事先定义好的]
//        popupwindow.setAnimationStyle(R.style.popupDialog);
//        popupwindow.showAsDropDown(Rl_title);
//        //初始化数据
//        //声明和初始化组件
//        LinearLayout mLl_one = (LinearLayout) customView.findViewById(R.id.ll_one);
//        LinearLayout  mLl_two = (LinearLayout) customView.findViewById(R.id.ll_two);
//        LinearLayout mLl_three = (LinearLayout) customView.findViewById(R.id.ll_three);
//        LinearLayout mLl_four = (LinearLayout) customView.findViewById(R.id.ll_four);
//        LinearLayout mLl_five = (LinearLayout) customView.findViewById(R.id.ll_five);
//        LinearLayout mLl_six = (LinearLayout) customView.findViewById(R.id.ll_six);
//        LinearLayout ll_show = (LinearLayout) customView.findViewById(R.id.ll_show);
////        Button mBtn_cancel = (Button) view.findViewById(R.id.btn_cancel);
//        // 自定义view添加触摸事件
////        customView.setOnTouchListener(new View.OnTouchListener() {
////            @Override
////            public boolean onTouch(View v, MotionEvent event) {
////                if (popupwindow != null && popupwindow.isShowing()) {
////                    popupwindow.dismiss();
////                    popupwindow = null;
////                }
////                return false;
////            }
////        });
////        popupwindow.setTouchInterceptor(new View.OnTouchListener() {
////            @Override
////            public boolean onTouch(View v, MotionEvent event) {
////                int height = customView.findViewById(R.id.ll_show).getTop();
////                int y=(int) event.getY();
////                if(event.getAction()==MotionEvent.ACTION_UP){
////                    if(y<height){
////                        popupwindow.dismiss();
////                    }
////                }
////                return true;
////            }
////        });
//        //设置点击事件
//        mLl_one.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mTv_repay_time.setText("1年12期");
//                popupwindow.dismiss();
//            }
//        });
////        mLl_one.setBackgroundResource(R.color.gray);
//        mLl_two.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mTv_repay_time.setText("2年24期");
//                popupwindow.dismiss();
//            }
//        });
//        mLl_three.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mTv_repay_time.setText("3年36期");
//                popupwindow.dismiss();
//            }
//        });
//        mLl_four.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mTv_repay_time.setText("4年48期");
//                popupwindow.dismiss();
//            }
//        });
//        mLl_five.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mTv_repay_time.setText("5年60期");
//                popupwindow.dismiss();
//            }
//        });
//        mLl_six.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mTv_repay_time.setText("6年72期");
//                popupwindow.dismiss();
//            }
//        });
//        ll_show.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                popupwindow.dismiss();
//            }
//        });
//    }
//    //自定义dialog
//    private void showRepayTime(){
//        AlertDialog.Builder builder = new AlertDialog.Builder(this);
//        final AlertDialog dialog = builder.create();
//        View view = View.inflate(this, R.layout.dialog_repay_time, null);// 给dialog设定特定布局
//        // dialog.setView(view);
//        dialog.setView(view, 0, 0, 0, 0);// 去掉上下左右边距, 兼容2.x版本
//        //声明和初始化组件
//        LinearLayout mLl_one = (LinearLayout) view.findViewById(R.id.ll_one);
//        LinearLayout  mLl_two = (LinearLayout) view.findViewById(R.id.ll_two);
//        LinearLayout mLl_three = (LinearLayout) view.findViewById(R.id.ll_three);
//        LinearLayout mLl_four = (LinearLayout) view.findViewById(R.id.ll_four);
//        LinearLayout mLl_five = (LinearLayout) view.findViewById(R.id.ll_five);
//        LinearLayout mLl_six = (LinearLayout) view.findViewById(R.id.ll_six);
////        Button mBtn_cancel = (Button) view.findViewById(R.id.btn_cancel);
//        //设置点击事件
//        mLl_one.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mTv_repay_time.setText("1年12期");
//                dialog.dismiss();
//            }
//        });
////        mLl_one.setBackgroundResource(R.color.gray);
//        mLl_two.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mTv_repay_time.setText("2年24期");
//                dialog.dismiss();
//            }
//        });
//        mLl_three.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mTv_repay_time.setText("3年36期");
//                dialog.dismiss();
//            }
//        });
//        mLl_four.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mTv_repay_time.setText("4年48期");
//                dialog.dismiss();
//            }
//        });
//        mLl_five.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mTv_repay_time.setText("5年60期");
//                dialog.dismiss();
//            }
//        });
//        mLl_six.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mTv_repay_time.setText("6年72期");
//                dialog.dismiss();
//            }
//        });
////        mBtn_cancel.setOnClickListener(new View.OnClickListener() {
////            @Override
////            public void onClick(View v) {
////                dialog.dismiss();
////            }
////        });
//        Window window = dialog.getWindow();
//        // 设置显示动画
//        window.setWindowAnimations(R.style.popupDialog);
//        WindowManager.LayoutParams wl = window.getAttributes();
//        wl.x = 0;
//        wl.y =getWindowManager().getDefaultDisplay().getHeight();
//        // 以下这两句是为了保证按钮可以水平满屏
//        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
//        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;
//        // 设置显示位置
//        dialog.onWindowAttributesChanged(wl);
//        // 设置点击外围解散
//        dialog.setCanceledOnTouchOutside(true);
//        dialog.show();
//    }
    TextWatcher mTextWatcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//            //输入之前
//            String mMoney = mTv_count_money.getText().toString().trim();
//            if () {
//                oldHistory = 0;
//            } else {
//                oldHistory = Integer.getInteger(mMoney);
//            }
    }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.toString().equals("")) {
                mTv_total_money.setText("0");
                mTv_repay_month.setText("0");
                mTv_extra_expense.setText("0");
            } else {
                if(mTv_repay_time.getText().toString()=="1年12期") {
                    //本金
                    loan_money = Double.parseDouble(mEt_repay_money.getText().toString());
                    //年利率
                    year_rate = (Double.parseDouble(mEt_repay_rate.getText().toString())) / 100.0;
                    //月利率
                    month_rate = year_rate / 12.0;
                    getTotalMoney(loan_money, month_rate, 12.0);
                }else if(mTv_repay_time.getText().toString()=="2年24期"){
                    //本金
                    loan_money = Double.parseDouble(mEt_repay_money.getText().toString());
                    //年利率
                    year_rate = (Double.parseDouble(mEt_repay_rate.getText().toString())) / 100.0;
                    //月利率
                    month_rate = year_rate / 12.0;
                    getTotalMoney(loan_money, month_rate, 24.0);
                }else if(mTv_repay_time.getText().toString()=="3年36期"){
                    //本金
                    loan_money = Double.parseDouble(mEt_repay_money.getText().toString());
                    //年利率
                    year_rate = (Double.parseDouble(mEt_repay_rate.getText().toString())) / 100.0;
                    //月利率
                    month_rate = year_rate / 12.0;
                    getTotalMoney(loan_money, month_rate, 36.0);
                }else if(mTv_repay_time.getText().toString()=="4年48期"){
                    //本金
                    loan_money = Double.parseDouble(mEt_repay_money.getText().toString());
                    //年利率
                    year_rate = (Double.parseDouble(mEt_repay_rate.getText().toString())) / 100.0;
                    //月利率
                    month_rate = year_rate / 12.0;
                    getTotalMoney(loan_money, month_rate, 48.0);
                }else if(mTv_repay_time.getText().toString()=="5年60期"){
                    //本金
                    loan_money = Double.parseDouble(mEt_repay_money.getText().toString());
                    //年利率
                    year_rate = (Double.parseDouble(mEt_repay_rate.getText().toString())) / 100.0;
                    //月利率
                    month_rate = year_rate / 12.0;
                    getTotalMoney(loan_money, month_rate, 60.0);
                }else if(mTv_repay_time.getText().toString()=="6年72期"){
                    //本金
                    loan_money = Double.parseDouble(mEt_repay_money.getText().toString());
                    //年利率
                    year_rate = (Double.parseDouble(mEt_repay_rate.getText().toString())) / 100.0;
                    //月利率
                    month_rate = year_rate / 12.0;
                    getTotalMoney(loan_money, month_rate, 72.0);
                }
        }
    }

    @Override
    public void afterTextChanged(Editable s) {

    }
};
    /**
     * 设置添加屏幕的背景透明度
     * @param bgAlpha
     */
    public void backgroundAlpha(float bgAlpha)
    {
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.alpha = bgAlpha; //0.0-1.0
        getWindow().setAttributes(lp);
    }
}
